package dao.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class DAOHibernate {
	
	private static SessionFactory sessionFactory = null;
	
	public Session connect()
	{
		if(sessionFactory == null)
			sessionFactory = new Configuration().configure("dao/hibernate/hibernate.cfg.xml").buildSessionFactory();
			
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		
		return session;
	}
	
	public void close(Session session)
	{
		session.getTransaction().commit();
		session.close();
	}
	
	public void cancel(Session session)
	{
		session.getTransaction().rollback();
		session.close();
	}
}
